
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;

using Swaf;
using Swaf.Container;

namespace Swaf.BizObj
{
	[Serializable]
	public class ValidationError : INameAddressSupport
	{
		public string BizObjType;
		public string FieldName;
		public string DefaultMsg;
		public object InvalidValue;

		public ValidationError(string bizObjType, string fieldName, string defMsg, object invalidVal)
		{
			BizObjType = bizObjType;
			FieldName = fieldName;
			DefaultMsg = defMsg;
			InvalidValue = invalidVal;
		}

		public object get(string name)
		{
			return GetType().InvokeMember(name,
				System.Reflection.BindingFlags.IgnoreCase | System.Reflection.BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetField, null, this, null);
		}

		public object get(string name, object oneArg)
		{
			return get(name);
		}

		public object get(string name, params object[] p)
		{
			return get(name);
		}

		public void put(string name, object newValue)
		{
			GetType().InvokeMember(name,
				System.Reflection.BindingFlags.IgnoreCase | System.Reflection.BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetField, null, this, new object[] { newValue });
		}

		public void put(string nameAddress, object val, object extraInfo)
		{
			put(nameAddress, val);
		}

		public bool isGetOnly
		{
			get { return false; }
		}

		public XmlSerializationSupport SerializationSupport
		{
			get { throw new Exception("The method or operation is not implemented."); }
		}

		public string Xml
		{
			get { throw new Exception("The method or operation is not implemented."); }
		}

		public string getXml(string options)
		{
			throw new Exception("The method or operation is not implemented.");
		}

		public bool containsField(string nameAddress)
		{
			MemberInfo[] mi = GetType().GetMember(nameAddress);
			return mi != null && mi.Length != 0;
		}

		public System.Collections.IEnumerator GetEnumerator()
		{
			throw new Exception("The method or operation is not implemented.");
		}
	}
}
